package edu.pw.treegrid.server.filter;

import org.w3c.dom.Element;

import edu.pw.treegrid.server.reportmodel.Report;


public class FilterDeserializer {

	public static Filter newFilter(Element filterElement, Report report) {
		Filter result = null;
		String name = filterElement.getNodeName().toUpperCase();
		
		if(name.equals(OperatorType.AND.toString())) {
			result = new AndFilter();
		}
		else if(name.equals(OperatorType.OR.toString())) {
			result = new OrFilter();
		}
		else if(name.equals(OperatorType.EQ.toString())) {
			result = new EqFilter();
		}
		else if(name.equals(OperatorType.GT.toString())) {
			result = new GreaterFilter();
		}
		else if(name.equals(OperatorType.GTE.toString())) {
			result = new GreaterOrEqualFilter();
		}
		else if(name.equals(OperatorType.LIKE.toString())) {
			result = new LikeFilter();
		}
		else if(name.equals(OperatorType.LT.toString())) {
			result = new LowerFilter();
		}
		else if(name.equals(OperatorType.LTE.toString())) {
			result = new LowerOrEqualFilter();
		}
		
		result.deserializeFromXML(filterElement, report);
		
		return result;
	}
}
